package cn.cupk.corporateshuttlemanagesystem.service.Impl;

import cn.cupk.corporateshuttlemanagesystem.mapper.UserMapper;
import cn.cupk.corporateshuttlemanagesystem.pojo.Companies;
import cn.cupk.corporateshuttlemanagesystem.pojo.Users;
import cn.cupk.corporateshuttlemanagesystem.service.UserService;
import cn.cupk.corporateshuttlemanagesystem.utils.Md5Util;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class UserServiceImpl implements UserService {

    @Autowired
    private UserMapper userMapper;
    @Override
    public Users findUserByUsername(String username) {
        return userMapper.findUserByUsername(username);
    }

    @Override
    public Companies findCompanyByName(String companyName) {
        return userMapper.findCompanyByName(companyName);
    }

    @Override
    public Companies findCompanyById(int companyId) {
        return userMapper.findCompanyById(companyId);
    }

    @Override
    public void addUser(Users user) {
        //获取公司Id
        Integer companyId = userMapper.findCompanyIdByName(user.getCompanyName());
        user.setCompanyId(companyId);

        user.setPassword(Md5Util.getMD5String(user.getPassword()));
        //添加用户
        userMapper.addUser(user);
    }

    @Override
    public void updateUser(Users user) {
        userMapper.updateUser(user);
    } //更新用户信息

    @Override
    public Users findUserById(Integer userId) {return userMapper.findUserById(userId);}
}
